package com.atg.atgchat.init.user.controller;


import com.atg.atgchat.init.common.utils.RequestContext;
import com.atg.atgchat.init.common.vo.response.ApiResult;
import com.atg.atgchat.init.user.model.dto.ModifyNameRequest;
import com.atg.atgchat.init.user.model.dto.RequestInfo;
import com.atg.atgchat.init.user.model.dto.WearingBadgeRequest;
import com.atg.atgchat.init.user.model.vo.BadgeVo;
import com.atg.atgchat.init.user.model.vo.UserInfoVo;
import com.atg.atgchat.init.user.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author author: atg
 * @since 2025-01-12
 */
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/userInfo")
    @ApiOperation("用户详情")
    public ApiResult<UserInfoVo> getUserInfo() {
        RequestInfo requestInfo = RequestContext.getRequestInfo();
        return ApiResult.success(userService.getUserInfo(requestInfo.getUid()));
    }

    // 修改名字
    @PutMapping("/name")
    @ApiOperation("修改名字")
    public ApiResult<Void> modifyName(@Valid @RequestBody ModifyNameRequest modifyNameRequest) {
        RequestInfo requestInfo = RequestContext.getRequestInfo();
        userService.modifyName(requestInfo.getUid(), modifyNameRequest.getName());
        return ApiResult.success();
    }

    // 显示可以佩戴的徽章
    @GetMapping("/badges")
    @ApiOperation("显示佩戴的徽章")
    public ApiResult<List<BadgeVo>> showBadges() {
        RequestInfo requestInfo = RequestContext.getRequestInfo();
        return ApiResult.success(userService.badges(requestInfo.getUid()));
    }
    // 佩戴徽章
    @PutMapping("/badge")
    @ApiOperation("佩戴徽章")
    public ApiResult<Void> wearingBadge(@Valid @RequestParam WearingBadgeRequest wearingBadgeRequest) {
        RequestInfo requestInfo = RequestContext.getRequestInfo();
        userService.wearBadge(requestInfo.getUid(), wearingBadgeRequest);
        return ApiResult.success();
    }

}

